<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
  <script src="../../js/common.js"></script>
  <style>
    .user_detail {
      margin-bottom: 1%;
      width: 100%;
      height: auto;
    }

    .mr10 {
      margin-right: 10%;
    }

    .color_gray {
      background-color: #F5F5F5;
    }
  </style>
</head>

<body>
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <div style="margin: 3%"></div>
      <div class="user_detail">
        <label class="layui-form-label">敏感词：</label>
        <div class="layui-input-block mr10">
          <input type="text" id="sensitive" value="" class="layui-input">
        </div>
      </div>
    </div>

    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      </div>
    </div>
  </form>

  <script src="../../layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript">

    // layui.use
    layui.use(['dropdown', 'util', 'layer', 'table'], function () {
      var dropdown = layui.dropdown
        , util = layui.util
        , layer = layui.layer
        , table = layui.table
        , $ = layui.$
        , form = layui.form
        , element = layui.element;

      //监听提交
      form.on('submit(formDemo)', function (data) {
        var sensitive = $('#sensitive')[0].value;
        if (sensitive.trim().length == 0) {
          layer.alert("敏感词不能为空", {
            title: '提示'
          });
          return false;
        }

        var sensitiveDto = {
          sensitive: sensitive
        }

        $.ajax({
          url: "/api/READ/api/my/sensitive/insert",
          type: "POST",
          traditional: true,//这使json格式的字符不会被转码
          contentType: 'application/json; charset=UTF-8',
          datatype: "json",
          headers: {
            token: localStorage.token
          },
          data: JSON.stringify(sensitiveDto),
          success: function (res) {

            if (res.code === '200') {
              layer.msg('添加成功');

            } else {
              layer.alert(res.msg, {
                title: '提示'
              });
              return false;
            }
          }
        })
        return false;
      });

      //初演示
      dropdown.render({
        elem: '.demo1'
        , data: [{
          title: name
          , id: 100

        }]
        , click: function (obj) {
          layer.tips('点击了：' + obj.title, this.elem, { tips: [1, '#5FB878'] })
        }
      });
    });
  </script>
</body>

</html>